<%@ page contentType="text/html;charset=UTF-8" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>

    <html>
    <head>
        <title>修改密码</title>
    <script>
        $(document).ready(function() {
            //聚焦第一个输入框
            $("#oldP").focus();
            //为inputForm注册validate函数
            $("#inputForm").validate({
                rules: {
                    oldP:{required: true ,minlength: 6},
                    newP:{required: true ,minlength: 6},
                    plainP:{required: true ,minlength: 6,equalTo: "#newP"}
                },
                messages: {
                    oldP:{
                        required:"旧密码不能为空",
                        minlength:"旧密码长度不能小于6位"
                    },
                    newP:{
                        required:"新密码不能为空",
                        minlength:"新密码长度不能小于4位"
                    },
                    plainP:{
                        required:"确认密码不能为空",
                        minlength:"确认密码长度不能小于4位",
                        equalTo: "请输入相同的密码"
                    }
                }
            });
            $("#submit_btn").click(function(){
                var oldP = $('#oldP').val();
                var newP = $('#newP').val();
                var plainP = $('#plainP').val();

                if(newP !=plainP)
                {
                    alert("新密码和确认密码不一致");
                    return;
                }
                var url = "${ctx}/settings/updatePwd";
                $.post(url,{"oldP":oldP,"newP":newP},function(data){
                    alert(data.message);
                },"json");
            });
        });
    </script>

</head>

<body>
<div class="container">
    <div class="content">
        <form id="inputForm" action="" method="post" class="form-horizontal">
            <div class="form-group">
                <h3 class="item-title">修改密码</h3>

                <div class="form-item">
                    <label for="">旧密码</label>
                    <input type="password" class="form-control" id="oldP" name="oldP" placeholder="旧密码">
                </div>
                <div class="form-item">
                    <label for="">新密码</label>
                    <input type="password" class="form-control" id="newP" name="newP" required placeholder="新密码">
                </div>
                <div class="form-item">
                    <label for="">确认密码</label>
                    <input type="password" class="form-control" id="plainP" name="plainP" required placeholder="确认密码">
                    <!--
                    <p class="help-block">两次密码输入不一致</p>
                    -->
                </div>
            </div>
            <div>
                <input id="submit_btn" class="btn btn-primary" type="button" value="保存"/>&nbsp;
            </div>
        </form>
    </div>
</div>
</body>
</html>